package top.yuzt.animalserver.controller;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import top.yuzt.animalserver.entity.Animal;
import top.yuzt.animalserver.entity.Feed;
import top.yuzt.animalserver.mapper.AnimalMapper;
import top.yuzt.animalserver.mapper.FeedMapper;
import top.yuzt.animalserver.service.impl.AnimalServiceImpl;
import top.yuzt.animalserver.service.impl.FeedServiceImpl;

import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

@RestController
@RequestMapping("/watch")
public class AnimalWatchController {

    @Autowired
    private AnimalMapper animalMapper;
    @Autowired
    private AnimalServiceImpl animalService;
    @Autowired
    private FeedServiceImpl feedService;
    @Autowired
    private FeedMapper feedMapper;
    @GetMapping("/getlist")
    public Vector<Double> getfeedlist(Integer id){
       List<Feed> feedList = feedMapper.findByAnimalid(id);
        Vector<Double> vector = new Vector<Double>();
        for (Feed feed : feedList){
            vector.add(feed.getAnimalAddWeigh());
        }
        while (vector.size() < 7){
            vector.add(0d);
        }
        return vector;
    }
    @GetMapping("/getaverage")
    public String[] getAverage(){
        List<String> animaltype = getypelist();
        
        return null;
    }

    @GetMapping("/size")
    public int getsize(){
        return animalMapper.findByHealth("3").size();
    }

    private  List<String> getypelist(){
        List<String> strings = new ArrayList<>();
        for (Animal animal : animalService.list()){
            if(!strings.contains(animal.getType())){
                strings.add(animal.getType());
            }
        }
        return strings;
    }
}
